import { Jimp, intToRGBA } from "jimp";
import { Image } from "./hp3-img.js";

export async function loadImage(file:string):Promise<Image>{
    const image = await Jimp.read(file);
    const rst:Image = {
        width: image.width,
        height: image.height,
        pixels: []
    }
    for(let y=0; y<image.height; y++){
        for(let x=0; x<image.width; x++){
            const rgba = intToRGBA(image.getPixelColor(x,y));
            rst.pixels.push({
                r: rgba.r,
                g: rgba.g,
                b: rgba.b,
                a: rgba.a
            });
        }
    }
    return rst;
}
